package com.knowif.backend.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.pojo.UserCommentExample;
import com.knowif.pojo.UserOrder;
import com.knowif.pojo.UserOrderExample;
import com.knowif.search.SearchCondition;
import com.knowif.service.UserOrder_service;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;

/**
 * @author xingyao
 * @Description: 订单管理服务层
 */
@Service
public class UserOrderService {
	
	@Autowired
	private UserOrder_service userOrder_service;
	
	/**
	 * @author: xingyao 
	 * @Description:  对订单进行评分
	 * @param userOrder
	 * @return
	 */
	public RestBean<?> orderStar(UserOrder userOrder){
		return userOrder_service.orderStar(userOrder);
	}
	
	
	 /**
     * @author: xingyao 
     * @Description:  查看导师订单及其评论
     * @param searchCondition
     * @return
     * @throws Exception 
     */
    public RestBean<?> selectOrderComment(SearchCondition searchCondition) throws Exception{
    	if(searchCondition == null){
    		return RestBean.buildError("请输入要查找的导师id");
    	}
    	UserCommentExample userCommentExample = ExampleUtil.buildExample(new UserCommentExample(), searchCondition);
    	Integer userId = (Integer) searchCondition.getContitionValue("userId1");
    	if(userId == null){
    		return RestBean.buildError("请填写用户id", RestBean.NOTUSERID);
    	}
    	return userOrder_service.selectOrderDetail(userCommentExample, userId);
    }

	/**
	 * @author: xh
	 * @Description:  查询订单
	 * @param searchCondition
	 * @return
	 * @throws Exception
	 */
	public RestBean<?> selectOrder(SearchCondition searchCondition) throws Exception{
		if(searchCondition == null){
			return RestBean.buildError("请输入要查找订单信息");
		}
		UserOrderExample userOrderExample = null;
		userOrderExample = ExampleUtil.buildExample(new UserOrderExample(), searchCondition);
		return RestBean.build(RestBean.success_code,"", userOrder_service.selectByExampleAndNotVirtual(userOrderExample));
	}

	/**
	 * @author: xh
	 * @Description:  查询订单
	 * @param searchCondition
	 * @return
	 * @throws Exception
	 */
	public RestBean<?> selectOrderDetail(SearchCondition searchCondition) throws Exception{
		if(searchCondition == null){
			return RestBean.buildError("请输入要查找订单信息");
		}
		UserOrderExample userOrderExample = null;
		userOrderExample = ExampleUtil.buildExample(new UserOrderExample(), searchCondition);
		return RestBean.build(RestBean.success_code,"", userOrder_service.selectUserOrderDetail(userOrderExample));
	}


}
